package pers.crayon.baseprogram.util;

import java.util.Base64;

public class EncodeUtils {

    private EncodeUtils() {
    }

    /**
     * Encrypt base 64 string.
     *
     * @param key the key
     * @return the string
     * @throws Exception the exception
     */
    public static String encryptBASE64(byte[] key) {
        String base64encodedString = Base64.getEncoder().encodeToString(key);
        return base64encodedString.replaceAll("[\\s*\t\n\r]", "");
    }

    /**
     * Decrypt base 64 byte [ ].
     *
     * @param key the key
     * @return the byte [ ]
     * @throws Exception the exception
     */
    public static byte[] decryptBASE64(String key) {
        return Base64.getDecoder().decode(key.replaceAll("[\\s*\t\n\r]", ""));
    }
}
